<!DOCTYPE html>
<html lang="zh-cn">
<head prefix="og: http://ogp.me/ns#">
  <meta charset="utf-8">
  <title>axios-retry|axios中文网 | axios</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Canonical links -->
  <link rel="canonical" href="http://axios-js.com/zh-cn/docs/axios-retry.html">
  <!-- Alternative links -->
  
    
      <link rel="alternative" hreflang="en" href="http://axios-js.com/docs/axios-retry.html">
    
      <link rel="alternative" hreflang="zh-cn" href="http://axios-js.com/zh-cn/docs/axios-retry.html">
    
  
  <!-- Icon -->
  <link rel="apple-touch-icon" sizes="57x57" href="http://www.axios-js.com/icon/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="114x114" href="http://www.axios-js.com/icon/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="72x72" href="http://www.axios-js.com/icon/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="144x144" href="http://www.axios-js.com/icon/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="60x60" href="http://www.axios-js.com/icon/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="120x120" href="http://www.axios-js.com/icon/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="76x76" href="http://www.axios-js.com/icon/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="152x152" href="http://www.axios-js.com/icon/apple-touch-icon-152x152.png">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-196x196.png" sizes="196x196">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-160x160.png" sizes="160x160">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-16x16.png" sizes="16x16">
  <link rel="icon" type="image/png" href="http://www.axios-js.com/icon/favicon-32x32.png" sizes="32x32">
  <meta name="msapplication-TileColor" content="#2f83cd">
  <meta name="msapplication-TileImage" content="/icon/mstile-144x144.png">
  <meta name="generator" content="Hexo 4.1.0">
  <!-- CSS -->
  <!-- build:css build/css/navy.css -->
  
<link rel="stylesheet" href="static/css/navy.css">

  <!-- endbuild -->
  <link href="static/css/css.css" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="static/css/font-awesome.min.css">
  <link rel="stylesheet" href="static/css/docsearch.min.css">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css">
  <!-- RSS -->
  <link rel="alternate" href="http://www.axios-js.com/atom.xml" title="axios">
  <!-- Open Graph -->
  <meta name="description" content="axios-retry中文文档">
<meta property="og:type" content="website">
<meta property="og:title" content="axios-retry|axios中文网">
<meta property="og:url" content="http://axios-js.com/zh-cn/docs/axios-retry.html">
<meta property="og:site_name" content="axios">
<meta property="og:description" content="axios-retry中文文档">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://travis-ci.org/softonic/axios-retry.svg?branch=master">
<meta property="og:image" content="https://res.cloudinary.com/dq9x329zv/image/upload/v1589976730/6c2b0663-efd0-43de-8acb-15dac69ecb52_gm5yvs.jpg">
<meta property="og:image" content="http://axios-js.com/icon/les01.jpeg">
<meta property="og:image" content="http://axios-js.com/icon/les02.jpeg">
<meta property="og:image" content="http://axios-js.com/icon/les03.jpeg">
<meta property="og:image" content="http://axios-js.com/icon/les04.jpeg">
<meta property="article:published_time" content="2021-05-30T00:58:30.000Z">
<meta property="article:modified_time" content="2021-05-30T00:58:30.000Z">
<meta property="article:author" content="Hexo">
<meta property="article:tag" content="axios 中文">
<meta property="article:tag" content=" axios 中文文档">
<meta property="article:tag" content=" axios API 中文">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://travis-ci.org/softonic/axios-retry.svg?branch=master">
  <!-- Analytics -->
  
<script>
    (function(h,o,t,j,a,r){
        h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
        h._hjSettings={hjid:1120304,hjsv:6};
        a=o.getElementsByTagName('head')[0];
        r=o.createElement('script');r.async=1;
        r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
        a.appendChild(r);
    })(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
</script>

<a title="Real Time Web Analytics" href="javascript:;" target="_blank" rel="noopener"><img src="static/picture/badge.gif" border="0"></a>
<script>var clicky_site_ids = clicky_site_ids || []; clicky_site_ids.push(101192693);</script>
<script async="" src="static/js/js.js"></script>



</head>

<body>
  <div id="container">
    <header id="header" class="wrapper">
  <div id="header-inner" class="inner">
    <h1 id="logo-wrap">
      <a href="index.html" id="logo">axios</a>
    </h1>
    <nav id="main-nav">
      <a href="index1.html" class="main-nav-link">文档</a><a href="index2.html" class="main-nav-link">博客</a>
      <a href="javascript:;" target="_blank" rel="noopener" class="main-nav-link"><i class="fa fa-github-alt"></i></a>
      <div id="search-input-wrap">
        <div id="search-input-icon">
          <i class="fa fa-search"></i>
        </div>
        <input type="search" id="search-input" placeholder="Search...">
      </div>
    </nav>
    <div id="lang-select-wrap">
      <label id="lang-select-label"><i class="fa fa-globe"></i><span>简体中文</span></label>
      <select id="lang-select" data-canonical="docs/axios-retry.html">
        
          <option value="en">undefined</option>
        
          <option value="zh-cn" selected="">简体中文</option>
        
      </select>
    </div>
    <a id="mobile-nav-toggle">
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
    </a>
  </div>
</header>

    <div id="content-wrap">
  <div id="content" class="wrapper">
    <div id="content-inner">
      <article class="article-container" itemscope="" itemtype="http://schema.org/Article">
        <div class="article-inner">
          <div class="article">
            <div class="inner">
              <header class="article-header">
                <h1 class="article-title" itemprop="name">axios-retry|axios中文网</h1>
                <a href="javascript:;" target="_blank" rel="noopener" class="article-edit-link" title="改进本文"></a>
              </header>
              <div class="article-content" itemprop="articleBody">
                <p class="vultr-desc">
                  本站由axios爱好者共建，部署在vultr vps上，推荐使用vultr!价格实惠，实力雄厚。
                  最近新注册用户充值$25,可额外获赠$50,搭建博客必备。
                  <a href="javascript:;" target="_blank" rel="noopener">前往注册</a>
                </p>

                <div id="lagou-vip">
                  <a href="javascript:;" target="_blank" rel="noopener">京东双11，现在不买等一年！犒劳自己--></a>
                </div>
                <h1 id="axios-retry" class="article-heading"><a href="#axios-retry" class="headerlink" title="axios-retry"></a>axios-retry<a class="article-anchor" href="#axios-retry" aria-hidden="true"></a></h1><p><a href="javascript:;" target="_blank" rel="noopener"><img src="static/picture/react-axios1.svg" alt="Build Status"></a></p>
<p>Axios 插件 重试失败的请求</p>
<p><a href="javascript:;" target="_blank" rel="noopener"><br>  <img width="300" src="https://res.cloudinary.com/dq9x329zv/image/upload/v1589976730/6c2b0663-efd0-43de-8acb-15dac69ecb52_gm5yvs.jpg"><br></a></p>
<h2 id="安装" class="article-heading"><a href="#安装" class="headerlink" title="安装"></a>安装<a class="article-anchor" href="#安装" aria-hidden="true"></a></h2><figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm install axios-retry</span><br></pre></td></tr></table></figure>
<h2 id="使用" class="article-heading"><a href="#使用" class="headerlink" title="使用"></a>使用<a class="article-anchor" href="#使用" aria-hidden="true"></a></h2><figure class="highlight js"><table><tr><td class="code"><pre><span class="line"><span class="comment">// CommonJS</span></span><br><span class="line"><span class="comment">// const axiosRetry = require('axios-retry');</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// ES6</span></span><br><span class="line"><span class="keyword">import</span> axiosRetry <span class="keyword">from</span> <span class="string">'axios-retry'</span>;</span><br><span class="line"></span><br><span class="line">axiosRetry(axios, &#123; <span class="attr">retries</span>: <span class="number">3</span> &#125;);</span><br><span class="line"></span><br><span class="line">axios.get(<span class="string">'http://example.com/test'</span>) <span class="comment">// The first request fails and the second returns 'ok'</span></span><br><span class="line">  .then(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">    result.data; <span class="comment">// 'ok'</span></span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Exponential back-off retry delay between requests</span></span><br><span class="line">axiosRetry(axios, &#123; <span class="attr">retryDelay</span>: axiosRetry.exponentialDelay&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// Custom retry delay</span></span><br><span class="line">axiosRetry(axios, &#123; <span class="attr">retryDelay</span>: <span class="function">(<span class="params">retryCount</span>) =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> retryCount * <span class="number">1000</span>;</span><br><span class="line">&#125;&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 自定义 axios 实例</span></span><br><span class="line"><span class="keyword">const</span> client = axios.create(&#123; <span class="attr">baseURL</span>: <span class="string">'http://example.com'</span> &#125;);</span><br><span class="line">axiosRetry(client, &#123; <span class="attr">retries</span>: <span class="number">3</span> &#125;);</span><br><span class="line"></span><br><span class="line">client.get(<span class="string">'/test'</span>) <span class="comment">// 第一次请求失败，第二次成功</span></span><br><span class="line">  .then(<span class="function"><span class="params">result</span> =&gt;</span> &#123;</span><br><span class="line">    result.data; <span class="comment">// 'ok'</span></span><br><span class="line">  &#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 允许 request-specific 配置</span></span><br><span class="line">client</span><br><span class="line">  .get(<span class="string">'/test'</span>, &#123;</span><br><span class="line">    <span class="string">'axios-retry'</span>: &#123;</span><br><span class="line">      retries: <span class="number">0</span></span><br><span class="line">    &#125;</span><br><span class="line">  &#125;)</span><br><span class="line">  .catch(<span class="function"><span class="params">error</span> =&gt;</span> &#123; <span class="comment">// The first request fails</span></span><br><span class="line">    error !== <span class="literal">undefined</span></span><br><span class="line">  &#125;);</span><br></pre></td></tr></table></figure>
<p><strong>备注:</strong> 除非 <code>shouldResetTimeout</code>被设置, 这个插件<br>将请求超时解释为全局值, 不是针对每一个请求，二是全局的设置</p>
<h2 id="配置" class="article-heading"><a href="#配置" class="headerlink" title="配置"></a>配置<a class="article-anchor" href="#配置" aria-hidden="true"></a></h2><table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>retries</td>
<td><code>Number</code></td>
<td><code>3</code></td>
<td>The number of times to retry before failing.</td>
</tr>
<tr>
<td>retryCondition</td>
<td><code>Function</code></td>
<td><code>isNetworkOrIdempotentRequestError</code></td>
<td>如果应该重试请求，则进一步控制的回调。默认情况下，如果是幂等请求的网络错误或5xx错误，它会重试(GET, HEAD, OPTIONS, PUT or DELETE).</td>
</tr>
<tr>
<td>shouldResetTimeout</td>
<td><code>Boolean</code></td>
<td>false</td>
<td>Defines if the timeout should be reset between retries</td>
</tr>
<tr>
<td>retryDelay</td>
<td><code>Function</code></td>
<td><code>function noDelay() { return 0; }</code></td>
<td>控制重试请求之间的延迟。默认情况下，重试之间没有延迟。另一个选项是exponentialDelay (<a href="javascript:;" target="_blank" rel="noopener">Exponential Backoff</a>). The function is passed <code>retryCount</code> and <code>error</code>.</td>
</tr>
</tbody>
</table>
<h2 id="测试" class="article-heading"><a href="#测试" class="headerlink" title="测试"></a>测试<a class="article-anchor" href="#测试" aria-hidden="true"></a></h2><p>克隆这个仓库 然后 执行:</p>
<figure class="highlight bash"><table><tr><td class="code"><pre><span class="line">npm <span class="built_in">test</span></span><br></pre></td></tr></table></figure>
<h2 id="贡献" class="article-heading"><a href="#贡献" class="headerlink" title="贡献"></a>贡献<a class="article-anchor" href="#贡献" aria-hidden="true"></a></h2><ol>
<li>Fork it: <code>git clone https://github.com/softonic/axios-retry.git</code></li>
<li>Create your feature branch: <code>git checkout -b feature/my-new-feature</code></li>
<li>Commit your changes: <code>git commit -am &#39;Added some feature&#39;</code></li>
<li>Check the build: <code>npm run build</code></li>
<li>Push to the branch: <code>git push origin my-new-feature</code></li>
<li>Submit a pull request :D</li>
</ol>
<div class="recommand">以下课程十分推荐想往前端架构师方向精进的同学，月入5万的梦想总要有的！投资自己就是最好的投资！</div><div class="lessonlist"><div class="lession"><a href="javascript:;" target="_blank" rel="noopener"><img src="static/picture/les01.jpeg" class="lesspic"></a></div><div class="lession"><a href="javascript:;" target="_blank" rel="noopener"><img src="static/picture/les02.jpeg" class="lesspic"></a></div><div class="lession"><a href="javascript:;" target="_blank" rel="noopener"><img src="static/picture/les03.jpeg" class="lesspic"></a></div><div class="lession"><a href="javascript:;" target="_blank" rel="noopener"><img src="static/picture/les04.jpeg" class="lesspic"></a></div></div>
              </div>
              <footer class="article-footer">
                <time class="article-footer-updated" datetime="2021-05-30T00:58:30.000Z" itemprop="dateModified">上次更新：2021-05-30</time>
                <a href="react-axios.html" class="article-footer-prev" title="react-axios"><i class="fa fa-chevron-left"></i><span>上一页</span></a><a href="vue-axios-plugin.html" class="article-footer-next" title="vue-axios-plugin"><span>下一页</span><i class="fa fa-chevron-right"></i></a>
              </footer>
              
            </div>
          </div>
          <aside id="article-toc" role="navigation">
            <div id="article-toc-inner">
              <strong class="sidebar-title">目录</strong>
              <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#axios-retry"><span class="toc-text">axios-retry</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#安装"><span class="toc-text">安装</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#使用"><span class="toc-text">使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#配置"><span class="toc-text">配置</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#测试"><span class="toc-text">测试</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#贡献"><span class="toc-text">贡献</span></a></li></ol></li></ol>
              <a href="#" id="article-toc-top">回到顶部</a>
            </div>
          </aside>
        </div>
      </article>
      <aside id="sidebar" role="navigation">
  <div class="inner">
    <strong class="sidebar-title">开始使用</strong><a href="index1.html" class="sidebar-link">概述</a><strong class="sidebar-title">框架整合</strong><a href="vue-axios.html" class="sidebar-link">vue-axios</a><a href="nuxtjs-axios.html" class="sidebar-link">nuxtjs-axios</a><a href="react-axios.html" class="sidebar-link">react-axios</a><strong class="sidebar-title">Plugins</strong><a href="" class="sidebar-link current">axios-retry</a><a href="vue-axios-plugin.html" class="sidebar-link">vue-axios-plugin</a>
  </div>
</aside>
    </div>
  </div>
</div>

    <footer id="footer" class="wrapper">
  <div class="inner">
    <div id="footer-copyright">
      &copy; 2021 axios中文网<br>
      Documentation licensed under <a href="javascript:;" target="_blank">CC BY 4.0</a>.
    </div>
    <div id="footer-links">
      <a href="javascript:;" class="footer-link" target="_blank"><i class="fa fa-twitter"></i></a>
      <a href="javascript:;" class="footer-link" target="_blank"><i class="fa fa-github-alt"></i></a>
    </div>
  </div>
</footer>

  </div>
  <div id="mobile-nav-dimmer"></div>
  <nav id="mobile-nav">
  <div id="mobile-nav-inner">
    <ul id="mobile-nav-list">
      <a href="index1.html" class="mobile-nav-link">文档</a><a href="index2.html" class="mobile-nav-link">博客</a>
      <li class="mobile-nav-item">
        <a href="javascript:;" class="mobile-nav-link" rel="external" target="_blank">GitHub</a>
      </li>
    </ul>
    
      <strong class="mobile-nav-title">开始使用</strong><a href="index1.html" class="mobile-nav-link">概述</a><strong class="mobile-nav-title">框架整合</strong><a href="vue-axios.html" class="mobile-nav-link">vue-axios</a><a href="nuxtjs-axios.html" class="mobile-nav-link">nuxtjs-axios</a><a href="react-axios.html" class="mobile-nav-link">react-axios</a><strong class="mobile-nav-title">Plugins</strong><a href="" class="mobile-nav-link current">axios-retry</a><a href="vue-axios-plugin.html" class="mobile-nav-link">vue-axios-plugin</a>
    
  </div>
  <div id="mobile-lang-select-wrap">
    <span id="mobile-lang-select-label"><i class="fa fa-globe"></i><span>简体中文</span></span>
    <select id="mobile-lang-select" data-canonical="docs/axios-retry.html">
      
        <option value="en">undefined</option>
      
        <option value="zh-cn" selected="">简体中文</option>
      
    </select>
  </div>
</nav>
  <!-- Scripts -->
<!-- build:js build/js/main.js -->

<script src="static/js/lang_select.js"></script>


<script src="static/js/toc.js"></script>


<script src="static/js/mobile_nav.js"></script>

<!-- endbuild -->

<!-- Algolia -->




<div class="popup-container">
  
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pure/1.0.1/pure-min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.min.css">
<style>
    #magic-popup {
        color: #000;
        
    }
    .vultr-coupon {
        margin-top: 20px
    }
    .popup-container {
        visibility: hidden;
        position: relative
    }

    .coupon {
        font-size: 16px;
    }
    .desc {
        margin-top: 10px;
        color: #03a9f4;
        font-size: 16px;
    }
    .reason {
        position: absolute;
        bottom: 0;
        right: 10px;
        width: 100%;
        font-size: 12px;
        color: red
    }

    .red-packet {
        display: flex;
        flex-direction: column;
        align-items: center;
    }
    #magic-popup{
        height: 200px
    }

    .campaign-tip {
        font-size: 14px;
        letter-spacing: 0
    }
</style>
<div class="popup-container">
<div id="magic-popup" class="magic-popup">
    <div class="pure-g"> 
            <a href="javascript:;" class="red-packet">
            <img width="150" src="https://res.cloudinary.com/dq9x329zv/image/upload/v1600435375/redpacket_n6cqu1.jpg">
            
            <span class="campaign-tip">拼多多新人专享红包！最高188元，限时领取！还有新人0元购，更多福利等你来拿~>></span>
            </a>
    </div>

    <!-- >
    <div class="pure-g">
            <div class="pure-u-12-24">
              <a class="pure-button pure-button-primary coupon" href="http://bit.ly/2PpdaHG" target="_blank" rel="noopener" class="btn btn-default btn-md" role="button">virmach特价vps</a>
            </div>

            <div class="pure-u-12-24">
              <a class="pure-button pure-button-primary coupon" href="http://bit.ly/2NDPn4N" target="_blank" rel="noopener" class="btn btn-default btn-md" role="button">vultr新户送$100</a>
            </div>
                
    </div>
    <div class="desc">
    vps可用来搭建博客，学习Linux，搭建个人网盘，私人git，
    可以搭建ssr一键使用google,搜索资料更方便。以上支持支付宝付款。
    </div>

    <div class="reason">
        广告费用用于支持本站服务器费用，希望大家理解
    </div> 

    <-->

    
    
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/8.11.8/sweetalert2.all.js"></script>
<script src="static/js/js.cookie.min.js"></script>

<script type="text/javascript">
var result = Cookies.get('popuped');
if(result){

} else {
Cookies.set('popuped', '1', { expires: 7 })
// Swal.fire({
//   title: '<strong></strong>',
//   icon: 'info',
//   html: $('#magic-popup'),
//   focusConfirm: false,
//   confirmButtonText: '知道了'
// })
}


</script>





</body>
</html>